import {login_req} from '@/api/user'
export default {
    namespaced: true,
    state:()=>({
        user_name:'',
        info:'',
        token:''
    }),
    mutations:{
        // 更新state当中的值
        updateLogin(state,{user_name,info,token}){
            state.user_name = user_name;
            state.info = info;
            state.token = token;
        }
    },
    actions:{
        // vuex当中的异步请求 放到actions
        // login请求放到actions中
        // login_a({commit},){}
        // login登录接口的ajax不在login组件 在actions,login_a中发送ajax  组件要触发login  mapActions中的对应的login_a触发
        async login_a({commit},{user_name,password}){
            let result = await login_req({user_name,password});//user_name password
            console.log(result);
            // 得到result之后 result.data info token    user_name

            commit('updateLogin',{user_name,info:result.data.info,token:result.data.token})
        }

    },
    getters:{}

}